<template>
	<view class="home-container">
		<swiper :autoplay="true" :indicator-dots="true" :interval="2000" :circular="true" style="height: 360rpx">

			<swiper-item>
				<image @click="$tab.navigateTo('/pages/home/know')" style="width: 100%;" mode="widthFix"
					src="@/static/images/index/home1.png" />
			</swiper-item>
			<swiper-item>
				<image @click="$tab.navigateTo('/pages/home/illegal')" style="width: 100%;" mode="widthFix"
					src="@/static/images/index/home2.png" />
			</swiper-item>

			<swiper-item>
				<view id="zxgg">
					<view id="nb">
						<p style="text-align: center;font-size: 18px;">通知</p>
						<p v-for="(item,index ) of threeNewNotice" style="margin: 5px;line-height: 30px;">
							{{ index+ 1 +'. '+item.noticeTitle}} — {{item.createTime}}
						</p>
					</view>
				</view>
			</swiper-item>
		</swiper>

		<view class="grid">
			<view class="grid-item" @click="$tab.navigateTo('/pages/home/member')">
				<view class="img"></view>
				<view class="desc">会员权益</view>
			</view>
			<view class="grid-item" @click="kefu()">
				<view class="img"></view>
				<view class="desc">客服中心</view>
			</view>
			<view class="grid-item" @click="$tab.navigateTo('/pages/home/invite?id=0')">
				<view class="img"></view>
				<view class="desc">邀请{{this.$auth.hasRole("general")?'注册':'代理'}}</view>
			</view>
			<view class="grid-item" @click="gzh()">
				<view class="img"></view>
				<view class="desc">关注公众号</view>
			</view>
		</view>

		<home-section title="个人产品" @more="moreProduct('个人')">
			<view class="section01">
				<view class="left">
					<view class="title">{{names[0].product_name}}</view>
					<view class="text">资产保全</view>
					<view class="text">涉案起诉</view>
					<view @click="handleMore(0)" class="btn">点击进入</view>
				</view>
				<view class="right">
					<view class="top">
						<view class="title">{{names[1].product_name}}</view>
						<view @click="handleMore(1)" class="btn">点击进入
						</view>
					</view>
					<view class="bottom">
						<view class="title">{{names[2].product_name}}</view>
						<view @click="handleMore(2)" class="btn">
							点击进入</view>
					</view>
				</view>
			</view>
		</home-section>

		<home-section title="企业产品" @more="moreProduct('企业')">
			<view @click="handleMore(3)" class="section02">
				<view class="title">
					{{names[3].product_name}}
				</view>
				<view class="desc">
					查询企业司法，税务，工商信息
				</view>
			</view>
		</home-section>

		<home-section title="婚恋风险" :showMore="false" v-if="names[4].del_flag == '0'">
			<view class="section03" @click="handleMore(4)">
				<view class="title">
					{{names[4].product_name}}
				</view>
				<view class="desc">
					婚姻真实性核验，已婚，未婚，离异，冷静期
				</view>
			</view>
		</home-section>

		<!-- 普通弹窗 -->
		<uni-popup ref="popup" background-color="#FFF" borderRadius="10px 10px 10px 10px">
			<view style="text-align: center;width: 80vw;padding: 10px;">
				<image mode="aspectFit" :src="imgSrc" />
				<p style="text-align: center;background-color: aliceblue;padding: 5px;">
					微信内长按识别或保存二维码微信扫一扫即可关注公众号（请勿取消关注公众号，否则无法第一时间获取到佣金消息通知）</p>
			</view>
		</uni-popup>

		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" :showClose="false" confirmText="我知道了" :title="firstUnRead.noticeTitle"
				:content="firstUnRead.noticeContent" @confirm="dialogConfirm" />
		</uni-popup>
	</view>
</template>

<script>
	import {
		productNames,
		QRCodeImg
	} from '@/api/index'
	import {
		readRecord,
		indexNotice
	} from '@/api/msg'

	export default {
		data() {
			return {
				names: [{
					product_id: null,
					product_name: ''
				}, {
					product_id: null,
					product_name: ''
				}, {
					product_id: null,
					product_name: ''
				}, {
					product_id: null,
					product_name: ''
				}, {
					product_id: null,
					product_name: '',
					del_flag: null
				}, {
					product_id: null,
					product_name: ''
				}],

				firstUnRead: {},
				threeNewNotice: [],

				QRURI: undefined,
				imgSrc: undefined
			}
		},
		created() {
			productNames().then(res => {
				this.names = res.data
				console.log('---this.names---',this.names)
				this.$forceUpdate();
			})
		},
		onLoad() {
			indexNotice(this.$store.state.user.userid).then(res => {
				if (res.firstUnRead) {
					this.firstUnRead = res.firstUnRead

					

					this.$refs.alertDialog.open('center')
				}
				this.threeNewNotice = res.threeNewNotice
			})
		},

		methods: {
			dialogConfirm() {
				readRecord({
					noticeId: this.firstUnRead.noticeId
				})
			},
			gzh() {
				QRCodeImg().then(res => {
					console.log('--QRCodeImg--', res)
					this.QRURI = res.url
					this.imgSrc = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + res.ticket
					this.$refs.popup.open('center')
				})
			},
			kefu() {
				window.location.href = "https://work.weixin.qq.com/kfid/kfc5aad73991502494d"
			},
			handleMore(index) {
				let item = this.names[index]
				if (item.status == '0') {
					this.$tab.navigateTo('/pages/home/popularize?id=' + item.product_id)
				} else {
					this.$modal.showToast(item.remark)
				}
			},
			moreProduct(typeNmae) {
				let num = 0
				for (var i = 0; i < this.names.length; i++) {
					let p = this.names[i]
					if (p.product_type == typeNmae) {
						num++
					}
				}
				if ((typeNmae == '个人' && num > 4) || (typeNmae == '企业' && num > 1)) {
					this.$tab.navigateTo('/pages/home/moreProduct?type=' + typeNmae)
				} else {
					this.$modal.showToast('暂无更多' + typeNmae + '产品')
				}
			}
		}
	}
</script>

<style lang="scss">
	.home-container {
		background-color: #F4F5FB;

		.grid {
			margin: 24rpx auto;
			width: 686rpx;
			height: 174rpx;
			border-radius: 12rpx;
			background-color: #fff;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.grid-item {
				display: flex;
				flex-direction: column;
				align-items: center;

				.img {
					width: 64rpx;
					height: 64rpx;
					background: url("@/static/images/index/grid-01.png") no-repeat center center;
					background-size: cover;
				}

				.desc {
					color: #333333;
					font-size: 24rpx;
					margin-top: 12rpx;
				}
			}

			.grid-item:nth-of-type(2) .img {
				background: url("@/static/images/index/grid-02.png") no-repeat center center;
				background-size: cover;
			}

			.grid-item:nth-of-type(3) .img {
				background: url("@/static/images/index/grid-03.png") no-repeat center center;
				background-size: cover;
			}

			.grid-item:nth-of-type(4) .img {
				background: url("@/static/images/index/grid-04.png") no-repeat center center;
				background-size: cover;
			}
		}

		.section01 {
			display: flex;
			justify-content: space-between;

			.title {
				color: #333333;
				font-size: 26rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
			}

			.btn {
				width: 120rpx;
				height: 40rpx;
				border-radius: 40rpx;
				background-color: rgba(38, 69, 194, 0.08);
				color: rgba(51, 51, 51, 0.40);
				font-size: 22rpx;
				font-family: PingFang SC, PingFang SC;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.left {
				padding: 16rpx 24rpx;
				box-sizing: border-box;
				width: 310rpx;
				height: 280rpx;
				background: url("@/static/images/index/section-left.png") no-repeat center center;
				background-size: contain;

				.text {
					color: rgba(51, 51, 51, 0.60);
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					margin-top: 16rpx;

					&:last-of-type {
						margin-top: 12rpx;
					}
				}

				.btn {
					margin-top: 12rpx;
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.top {
					padding: 16rpx 24rpx;
					box-sizing: border-box;
					width: 312rpx;
					height: 132rpx;
					background: url("@/static/images/index/section-right-top.png") no-repeat center center;
					background-size: contain;

					.btn {
						margin-top: 16rpx;
					}
				}

				.bottom {
					padding: 16rpx 24rpx;
					box-sizing: border-box;
					background: url("@/static/images/index/section-right-bottom.png") no-repeat center center;
					background-size: contain;

					.btn {
						margin-top: 16rpx;
					}
				}
			}
		}

		.section02 {
			height: 148rpx;
			border-radius: 8rpx;
			background: url("@/static/images/index/section02.png") no-repeat 438rpx 0,
				linear-gradient(to bottom, #F5F8FD 0, #E3EBFF 100%);
			background-size: contain;
			padding: 32rpx 24rpx;
			box-sizing: border-box;

			//display: flex;
			.title {
				color: #334D9E;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
			}

			.desc {
				color: rgba(51, 77, 158, 0.60);
				font-weight: 400;
				font-family: PingFang SC, PingFang SC;
				font-size: 24rpx;
				margin-top: 12rpx;
			}
		}

		.section03 {
			height: 148rpx;
			border-radius: 8rpx;
			background: url("@/static/images/index/section03.png") no-repeat right 10rpx,
				linear-gradient(to bottom, #FEFAF4 0, #FCF6ED 100%);
			background-size: contain;
			padding: 16rpx 24rpx;
			box-sizing: border-box;

			//display: flex;
			.title {
				color: #9E6D33;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
			}

			.desc {
				width: 342rpx;
				color: rgba(158, 109, 51, 0.60);
				font-weight: 400;
				font-family: PingFang SC, PingFang SC;
				font-size: 24rpx;
				margin-top: 8rpx;
			}
		}
	}

	#zxgg {

		height: 100%;
		background-image: url("@/static/images/banner/tz.png");
		/* 背景图垂直、水平均居中 */
		background-position: center center;
		/* 背景图不平铺 */
		background-repeat: no-repeat;
		/* 当内容高度大于图片高度时，背景图像的位置相对于viewport固定 */
		// background-attachment: fixed;
		/* 让背景图基于容器大小伸缩 */
		// background-size: cover;
		// padding-top: 35px;

		#nb {
			color: #fff;
			padding: 15px 10px;
			font-size: 15px;
		}
	}
</style>